package com.lida.zwservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lida.zwservice.entity.OneSubjectVo;
import com.lida.zwservice.entity.PersonalDetailedSubject;
import com.lida.zwservice.entity.TwoSubjectVo;
import com.lida.zwservice.mapper.PersonalDetailedSubjectMapper;
import com.lida.zwservice.service.PersonalDetailedSubjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 账务类别 服务实现类
 * </p>
 *
 * @author LiDa
 * @since 2022-01-26
 */
@Service
public class PersonalDetailedSubjectServiceImpl extends ServiceImpl<PersonalDetailedSubjectMapper, PersonalDetailedSubject> implements PersonalDetailedSubjectService {

    @Override
    public List<OneSubjectVo> selectSubject(String parentid) {
        QueryWrapper<PersonalDetailedSubject> wrapper =new QueryWrapper<>();
        wrapper.eq("parent_id",parentid);
        List<PersonalDetailedSubject> list =baseMapper.selectList(wrapper);

        List<OneSubjectVo> finaList = new ArrayList<OneSubjectVo>();

        for(int i = 0; i < list.size(); i++) {
            PersonalDetailedSubject oneDetailedSubject =list.get(i);
            OneSubjectVo oneSubject=new OneSubjectVo();
            BeanUtils.copyProperties(oneDetailedSubject,oneSubject);
            finaList.add(oneSubject);

            QueryWrapper<PersonalDetailedSubject> twowrapper =new QueryWrapper<>();
            twowrapper.eq("parent_id",oneDetailedSubject.getId());
            List<PersonalDetailedSubject> twolist =baseMapper.selectList(twowrapper);

            List<TwoSubjectVo> twoSubjectlist=new ArrayList<TwoSubjectVo>();
            for(int j = 0;j <twolist.size();j++){
                PersonalDetailedSubject twoDetailedSubject =twolist.get(j);
                TwoSubjectVo twoSubject=new TwoSubjectVo();
                BeanUtils.copyProperties(twoDetailedSubject,twoSubject);
                twoSubjectlist.add(twoSubject);
            }
            oneSubject.setTwoSubjectList(twoSubjectlist);
        }
        return finaList;
    }

    @Override
    public PersonalDetailedSubject getSubject(QueryWrapper<PersonalDetailedSubject> wrapperSubject) {
        PersonalDetailedSubject byId = baseMapper.selectById(wrapperSubject);

        System.out.println(byId);
        return byId;
    }
}
